#include "DY_HAL.h"




//#include "Util.h"
//bool _dy_thread_should_exit;
//bool dy_ran_overtime;
GPIO_t GPIO_instance;
//AnalogIn_t AnalogIn_instance;
//I2CDeviceManager_t i2c_mgr_instance;
//RCInput_t RCInput_instance;
//RCOutput_t RCOutput_instance;
//Scheduler_t Scheduler_instance;
//Semaphores_t Semaphores_instance;
//SPIDeviceManager_t spi_mgr_instance;
//Storage_t Storage_instance;
system_t system_instance;
UARTDriver_t UARTDriver_instance;
//Util_t Util_instance;

DY_HAL DY_HAL_instance;
//I2CDevice_t  MPU6050,MPU9250;
//SPIDevice_t  AS5048A_PITCH;
//SPIDevice_t  AS5048A_YAW;
GPIO_t       gpio_a;
void HAL_init(){
	SystemInit();
	bsp_gpio_init();
	bsp_uart_init();
//    gic_init();
	hrt_init();
	sbus_init();
//    iic_init(0);
//    SPI_init(0, 3);
//    rcout_init();
}
void HAL_constructs(DY_HAL *instance){
	GPIO_constructs(&GPIO_instance);
//	AnalogIn_constructs(&AnalogIn_instance);
//	I2CDeviceManager_constructs(&i2c_mgr_instance);
//	RCInput_constructs(&RCInput_instance);
//	RCOutput_constructs(&RCOutput_instance);
//	Scheduler_constructs(&Scheduler_instance);
//	Semaphores_constructs(&Semaphores_instance);
//	SPIDeviceManager_constructs(&spi_mgr_instance);
//	Storage_constructs(&Storage_instance);
	system_constructs(&system_instance);
	UARTDriver_constructs(&UARTDriver_instance);
//	Util_constructs(&Util_instance);

	instance->init = HAL_init;
	instance->GPIO = GPIO_instance;
//	instance->AnalogIn = AnalogIn_instance;
//	instance->i2c_mgr = i2c_mgr_instance;
//	instance->RCInput = RCInput_instance;
//	instance->RCOutput = RCOutput_instance;
//	instance->Scheduler = Scheduler_instance;
//	instance->Semaphores = Semaphores_instance;
//	instance->spi_mgr = spi_mgr_instance;
//	instance->Storage = Storage_instance;
	instance->system = system_instance;
	instance->UARTDriver = UARTDriver_instance;
//	instance->Util = Util_instance;
//	AS5048A_PITCH=instance->spi_mgr.get_device("AS5048A_PITCH");
//	AS5048A_YAW=instance->spi_mgr.get_device("AS5048A_YAW");
//	MPU6050=instance->i2c_mgr.get_device("mpu6000");
//	MPU9250=instance->i2c_mgr.get_device("mpu9250");
	
//	instance->Initial=&systemInit;

}
/*
  set the priority of the main APM task
 */
void hal_dy_set_priority(uint8_t priority){
    //vTaskPrioritySet(daemon_task, priority);
}
